<template>
	<view>
		<goods-list :goods="goods" @goodsItemClick="goGoodsDetail"></goods-list>
		<view v-if="flag" class="isOver">-----我是有底线的-----</view>
	</view>
</template>

<script>
	import goodsList from '../../components/goods-list/goods-list.vue'
	export default {
		data() {
			return {
				goods:[],
				pageindex:1,
				flag:false
			}
		},
		methods: {
			//获取商品列表的数据
			async getGoodsList(callBack){
				let res = await this.$myRequest({
					url:"/api/getgoods?pageindex="+this.pageindex
				})
				this.goods = [...this.goods, ...res.data.message]
				callBack && callBack();
			},
			goGoodsDetail(id){
				uni.navigateTo({
					url: '../goodsDetail/goodsDetail?id='+id
				})
			}
		},
		components:{goodsList},
		onLoad() {
			this.getGoodsList()			
		},
		onReachBottom(){
			if(this.goods.length < this.pageindex * 10) return this.flag = true
			this.pageindex++
			this.getGoodsList()				
		},
		onPullDownRefresh(){
			console.log('下拉刷新了')
			this.pageindex = 1
			this.goods = []
			this.flag = false
			setTimeout(()=>{
				this.getGoodsList(()=>{
					uni.stopPullDownRefresh()
				})
			},1000)
			
		}
		
	}
</script>

<style lang="scss">
	page{
		height: 100%;
		width: 100%;
		background:#e6e6e6;
	}
	.isOver{
		width: 100%;
		height: 50px;
		line-height: 50px;
		text-align: center;
		font-size: 32rpx;
	}
</style>
